{% macro ports(port_type,selected_types) -%}
{% if port_type["ports"][0] and port_type["ports"][0]["descr"] %}
    {% set port_name = port_type["ports"][0]["descr"] %}
{% elif port_type["ports"][0] and port_type["ports"][0]["name"] %}
    {% set port_name = port_type["ports"][0]["name"] %}
{% elif port_type["ports"][0] %}
    {% set port_name = "Lag w/o interfaces" %}
{%endif%}

{% set comma = joiner(",") -%}
{
  "current": {
    "tags": [],
    "text": "{% if port_type.type in selected_types %}Selected{% else %}All{% endif %}",
    "value": [
        "{%- for port in selected_types[port_type.type] %}{{port.name}},{% else %}$__all{% endfor %}"
     ]
  },
  "datasource": null,
  "hide": 0,
  "includeAll": true,
  "label": "{{port_type.name}}",
  "multi": true,
  "name": "{{port_type.type}}",
  "options": [
    {
      "selected": false,
      "text": "All",
      "value": "$__all"
    },
    {%for port in port_type.ports -%}
    {{ comma() }}{
      "selected": {%- if port.name in selected_types[port_type.type] -%}true{% else %}false{%- endif -%},
      "text": "{%- if port.descr -%}{{port.name}} status : {{ port.status }} ({{port.descr}}){%else%}{{port.name}} status : {{ port.status }}{%- endif -%}",
      "value": "{{port.name}}"
    }
    {%- endfor %}
   ],
  "query": "{%- for port in port_type.ports %}{{port.name}},{% endfor %}",
  "refresh": 0,
  "type": "custom"
}
{%- endmacro %}
